//
//  QLSystemNewsVC.m
//  神约
//
//  Created by qlwl on 17/2/6.
//  Copyright © 2017年 qlwl. All rights reserved.
//

#import "QLSystemNewsVC.h"
#import "ZJScrollPageView.h"
#import "QLNotificatMessageVC.h"

@interface QLSystemNewsVC ()<ZJScrollPageViewDelegate>
@property (nonatomic, strong) NSMutableArray * titleArray ; //
@property (nonatomic, weak) ZJScrollPageView * scrollPageView;
@end

@implementation QLSystemNewsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setNavTitle:@"消息"];
    [self setNavBarColor:NavBarTintColor];
    self.titleArray = [[NSMutableArray alloc] init];
    
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
    // 缩放标题
    style.scaleTitle = YES;
    style.contentViewBounces = NO;
    // 颜色渐变
    style.gradualChangeTitleColor = YES;
    // 设置附加按钮的背景图片
    // 初始化
    ZJScrollPageView *scrollPageView = [[ZJScrollPageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 49) segmentStyle:style titles:self.titleArray parentViewController:self delegate:self];
    scrollPageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    // 这里可以设置头部视图的属性(背景色, 圆角, 背景图片...)
    //    scrollPageView.segmentView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:scrollPageView];
    self.scrollPageView = scrollPageView;
    
    
    [self getData];
    
}
#pragma mark getScrollPageView

#pragma ZJScrollPageViewDelegate 代理方法
- (NSInteger)numberOfChildViewControllers {
    return self.titleArray.count;
}

- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index {
    
    UIViewController<ZJScrollPageViewChildVcDelegate> *childVc = reuseViewController;
    //    NSLog(@"%ld---------", index);
    if (childVc == nil) {
        childVc = [NSString instantiateViewControllerWithIdentifier:@"QLNotificatMessageVC" andSBName:@"News"];
    }
    return childVc;
}


- (void)scrollPageController:(UIViewController *)scrollPageController childViewControllWillAppear:(UIViewController *)childViewController forIndex:(NSInteger)index {
    NSLog(@"%ld ---将要出现",index);
}

- (void)scrollPageController:(UIViewController *)scrollPageController childViewControllDidAppear:(UIViewController *)childViewController forIndex:(NSInteger)index {
    NSLog(@"%ld ---已经出现",index);
}

- (void)scrollPageController:(UIViewController *)scrollPageController childViewControllWillDisappear:(UIViewController *)childViewController forIndex:(NSInteger)index {
    NSLog(@"%ld ---将要消失",index);
    
}


- (void)scrollPageController:(UIViewController *)scrollPageController childViewControllDidDisappear:(UIViewController *)childViewController forIndex:(NSInteger)index {
    NSLog(@"%ld ---已经消失",index);
    
}


- (void)getData
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        NSArray * titArray = @[@"邀约信息",@"单独邀约",@"打招呼",@"系统提示"];
        [self.titleArray addObjectsFromArray:titArray];
        [self.scrollPageView reloadWithNewTitles:self.titleArray];
    });
}




@end
